<template>
    <div>
        <el-card class="!border-none mb-4" shadow="never">
            <el-form
                class="mb-[-16px]"
                :model="queryParams"
                inline
            >
                <el-form-item label="用户信息" prop="user_id">
                    <el-input class="w-[280px]" v-model="queryParams.user_info" clearable placeholder="账号/邀请码" />
                </el-form-item>
                <el-form-item label="上级" prop="parent_id">
                    <el-input class="w-[280px]" v-model="queryParams.parent_info" clearable placeholder="账号/邀请码" />
                </el-form-item>
                <el-form-item label="代数" prop="level">
                    <el-input class="w-[280px]" v-model="queryParams.level" clearable placeholder="请输入代数" />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="resetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none" v-loading="pager.loading" shadow="never">
            <div class="mt-4">
                <el-table :data="pager.lists" @selection-change="handleSelectionChange">
                    <el-table-column label="用户">
						<template #default="{ row }">
							<div>账号：{{row.u1_mobile}}</div>
							<div>邀请码：{{row.u1_sn}}</div>
						</template>
					</el-table-column>
                    <el-table-column label="上级">
                    	<template #default="{ row }">
                    		<div>账号：{{row.u2_mobile}}</div>
                    		<div>邀请码：{{row.u2_sn}}</div>
                    	</template>
                    </el-table-column>
					<el-table-column label="层级">
						<template #default="{ row }">
							<div>一代：{{row.team_top.top_account}}</div>
							<div>代数：{{row.level}}代</div>
						</template>
					</el-table-column>
					<el-table-column label="余额" prop="u1_user_money"/>
					<el-table-column label="充提差">
						<template #default="{ row }">
							<div>充提差：
								<span v-if="row.u1_total_recharge - row.u1_total_withdraw < 0"
									class="text-danger font-bold">{{row.u1_total_recharge - row.u1_total_withdraw}}</span>
								<span
									v-if="row.u1_total_recharge - row.u1_total_withdraw >= 0">{{row.u1_total_recharge - row.u1_total_withdraw}}</span>
							</div>
						</template>
					</el-table-column>
					<el-table-column label="时间" prop="create_time" min-width="120" />
                </el-table>
            </div>
            <div class="flex mt-4 justify-end">
                <pagination v-model="pager" @change="getLists" />
            </div>
        </el-card>
    </div>
</template>

<script lang="ts" setup name="userRelationLists">
import { usePaging } from '@/hooks/usePaging'
import { apiUserRelationLists } from '@/api/user_relation'


// 查询条件
const queryParams = reactive({
    user_info: '',
    parent_info: '',
    level: '',
	type:''
})


// 分页相关
const { pager, getLists, resetParams, resetPage } = usePaging({
    fetchFun: apiUserRelationLists,
    params: queryParams
})

getLists()
</script>

